/**   
* @Title: PublicServiceImpl.java 
* @Package com.zjdiepu.www.biz.zpp 
* 
* @author zhangpp
* @date 2017年5月26日 上午10:37:15 
* @version V1.0   
*/
package com.zjdiepu.www.biz.zpp;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zjdiepu.www.dao.zpp.PublicDao;
import com.zjdiepu.www.ibiz.zpp.PublicService;
import com.zjdiepu.www.model.base.dto.DpBaseDataDictionary;
import com.zjdiepu.www.model.zpp.pub.ext.WhereSqlExt;

/**      
 * 项目名称：diepu-parent-biz   
 * 类名称：PublicServiceImpl   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年5月26日 上午10:37:15   
 * 修改人：zhangpp
 * 修改时间：2017年5月26日 上午10:37:15   
 * 修改备注：   
 * @version V1.0     
 */
@Service
public class PublicServiceImpl implements PublicService
{

	@Autowired
	private PublicDao publicDao;
	
	/* 
	* @author zhangpp
	* <p>Title: updateWhereSql</p> 
	* <p>Description: </p> 
	* @param whereSqlExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.PublicService#updateWhereSql(com.zjdiepu.www.model.zpp.pub.ext.WhereSqlExt) 
	* @version V1.0
	*/
	@Override
	public int updateWhereSql(WhereSqlExt whereSqlExt) {
		
		return publicDao.updateWhereSql(whereSqlExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: insertWhereSql</p> 
	* <p>Description: </p> 
	* @param whereSqlExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.PublicService#insertWhereSql(com.zjdiepu.www.model.zpp.pub.ext.WhereSqlExt) 
	* @version V1.0
	*/
	@Override
	public int insertWhereSql(WhereSqlExt whereSqlExt) {
		
		return publicDao.insertWhereSql(whereSqlExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: deleteWhereSql</p> 
	* <p>Description: </p> 
	* @param whereSqlExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.PublicService#deleteWhereSql(com.zjdiepu.www.model.zpp.pub.ext.WhereSqlExt) 
	* @version V1.0
	*/
	@Override
	public int deleteWhereSql(WhereSqlExt whereSqlExt) {
		
		return publicDao.updateWhereSql(whereSqlExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: selectWhereSql</p> 
	* <p>Description: </p> 
	* @param whereSqlExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.PublicService#selectWhereSql(com.zjdiepu.www.model.zpp.pub.ext.WhereSqlExt) 
	* @version V1.0
	*/
	@Override
	public List<Map<String, String>> selectWhereSql(WhereSqlExt whereSqlExt) {
		
		return publicDao.selectWhereSql(whereSqlExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: queryWhereSql</p> 
	* <p>Description: </p> 
	* @param sqlXmls
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.PublicService#queryWhereSql(java.lang.String) 
	* @version V1.0
	*/
	@Override
	public List<Map<String, String>> queryWhereSql(String sqlXmls) {
		
		return publicDao.queryWhereSql(sqlXmls);
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  getDictionaryName</p>  
	*  <p>Description:  </p>  
	*  @param name
	*  @param DataDicType
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.PublicService#getDictionaryName(java.lang.String, java.lang.String)  
	*  @version  V1.0
	*/
	@Override
	public String getDictionaryName(String name, String DataDicType) 
	{
		
		
		if(StringUtils.isBlank(name) || StringUtils.isBlank(DataDicType))
		{
			return "";
		}
		
		if(null == SystemServiceImpl.list || 0 == SystemServiceImpl.list.size())
		{
			SystemServiceImpl.list = new ArrayList<DpBaseDataDictionary>();
			String sqlXmls = "select t.id,t.parent_value,t.`name`,t.`value` from dp_base_data_dictionary t where t.dp_status = 1";
			List<Map<String, String>> list = publicDao.queryWhereSql(sqlXmls);
			if(null != list && list.size() > 0)
			{
				for(int i=0;i<list.size();i++)
				{
					Map<String, String> map = list.get(i);
					DpBaseDataDictionary dataDictionary = new DpBaseDataDictionary();
					dataDictionary.setId(map.get("id"));
					dataDictionary.setParentValue(map.get("parent_value"));
					dataDictionary.setName(map.get("name"));
					dataDictionary.setValue(map.get("value"));
					SystemServiceImpl.list.add(dataDictionary);
					dataDictionary = null;
				}
			}
		}
		
		List<DpBaseDataDictionary> dictionaries = new ArrayList<DpBaseDataDictionary>();
		
		if(null != SystemServiceImpl.list && SystemServiceImpl.list.size() > 0)
		{
			for(int i=0;i<SystemServiceImpl.list.size();i++)
			{
				DpBaseDataDictionary dataDictionary = SystemServiceImpl.list.get(i);
				
				if(StringUtils.isNotBlank(dataDictionary.getParentValue()))
				{
					if(DataDicType.equals(dataDictionary.getParentValue()))
					{
						dictionaries.add(dataDictionary);
					}
				}
			}
		}
		
		if(null != dictionaries && dictionaries.size() > 0)
		{
			for(int i=0;i<dictionaries.size();i++)
			{
				if(StringUtils.isNotBlank(dictionaries.get(i).getValue()))
				{
					if(name.equals(dictionaries.get(i).getValue()))
					{
						name =  dictionaries.get(i).getName();
						break;
					}
				}
			}
		}
		return name;
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  countSqlXmls</p>  
	*  <p>Description:  </p>  
	*  @param sqlXmls
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.PublicService#countSqlXmls(java.lang.String)  
	*  @version  V1.0
	*/
	@Override
	public int countSqlXmls(String sqlXmls) {
		
		return publicDao.countSqlXmls(sqlXmls);
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  getNameValues</p>  
	*  <p>Description:  </p>  
	*  @param DataDicType
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.PublicService#getNameValues(java.lang.String)  
	*  @version  V1.0
	*/
	@Override
	public Map<String, String> getNameValues(String DataDicType) 
	{
		
		
		if(StringUtils.isBlank(DataDicType))
		{
			return null;
		}
		
		Map<String, String> maps = new HashMap<String, String>(); 
		
		if(null != SystemServiceImpl.list && SystemServiceImpl.list.size() > 0)
		{
			for(int i=0;i<SystemServiceImpl.list.size();i++)
			{
				DpBaseDataDictionary dataDictionary = SystemServiceImpl.list.get(i);
				if(StringUtils.isNotBlank(dataDictionary.getParentValue()))
				{
					if(DataDicType.equals(dataDictionary.getParentValue()))
					{
						maps.put(dataDictionary.getValue(), dataDictionary.getName());
					}
				}
			}
		}
		return maps;
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  getDictionary</p>  
	*  <p>Description:  </p>  
	*  @param DicType  
	*  @see com.zjdiepu.www.ibiz.zpp.PublicService#getDictionary(java.lang.String)  
	*  @version  V1.0
	*/
	@Override
	public void getDictionary(String DicType) 
	{
		
		
		SystemServiceImpl.list = new ArrayList<DpBaseDataDictionary>();
		String sqlXmls = "select t.id,t.parent_value,t.`name`,t.`value` from dp_base_data_dictionary t where t.dp_status = 1";
		List<Map<String, String>> list = publicDao.queryWhereSql(sqlXmls);
		if(null != list && list.size() > 0)
		{
			for(int i=0;i<list.size();i++)
			{
				Map<String, String> map = list.get(i);
				DpBaseDataDictionary dataDictionary = new DpBaseDataDictionary();
				dataDictionary.setId(map.get("id"));
				dataDictionary.setParentValue(map.get("parent_value"));
				dataDictionary.setName(map.get("name"));
				dataDictionary.setValue(map.get("value"));
				SystemServiceImpl.list.add(dataDictionary);
				dataDictionary = null;
			}
		}
	}

	@Override
	public Map<String, String> selectMapsSql(String sqlXmls) {
		
		return publicDao.selectMapsSql(sqlXmls);
	}

	@Override
	public Map<String, Date> selectDateSql(String sqlXmls) {
		
		return publicDao.selectDateSql(sqlXmls);
	}

	@Override
	public List<Map<String, Double>> selectDoubleSql(String sqlXmls) {
		
		return publicDao.selectDoubleSql(sqlXmls);
	}
}
